package com.example.flink;

import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.kafka.clients.consumer.ConsumerConfig;

import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * ClassName: FlinkKafkaConsumerDemo
 * Package: com.example.flink
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-02
 * Time: 21:48
 */

//消费者集成
public class FlinkKafkaConsumerDemo {

    public static void main(String[] args) throws Exception {

        //获取环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(3);

        //创建kafka消费者
        Properties properties = new Properties();
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,"hadoop102:9092");
        //可以不写组ID
        properties.put(ConsumerConfig.GROUP_ID_CONFIG,"test");
        FlinkKafkaConsumer<String> first = new FlinkKafkaConsumer<>("first", new SimpleStringSchema(), properties);

        //3.流和消费者进行关联
        DataStreamSource<String> stringDataStreamSource = env.addSource(first);

        stringDataStreamSource.print();

        env.execute();


    }

}
